<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tìm kiếm</title>
<script type="text/javascript" src="java/kiemtratim.js"></script>
<script>
function validForm(){
var ten = document.getElementById('ten');
var filter = /[a-zA-Z0-9]/;
if(!filter.test(ten.value)){
document.tim.ten.focus();
return false;
}
}

</script>

</head>

<body>
<?php
include("kn.php");
if(!isset($_GET["hang"]))
{
$ten = $_POST["ten"];
$hang = $_POST["hang"];
}
else
{
$ten = $_GET["ten"];
$hang = $_GET["hang"];
}
$lenh = "select hinh,tenlaptop,tenhanglaptop,tenloai,concat(soluong,' Cái') as soluong,concat(format(dongia,0),' VNĐ') as dongia,mota from laptop,hanglaptop,loailaptop where laptop.mahanglaptop = hanglaptop.mahanglaptop and laptop.maloailaptop = loailaptop.maloailaptop and tenlaptop like '%$ten%' and laptop.mahanglaptop = '$hang'";
$kq = mysql_query($lenh);
$n = mysql_num_rows($kq);
if($n >0)
{
$tb = "Tím thấy ".$n." laptop";
}
else
{
$tb = "Không tìm thấy laptop nào!";

}
$sodong = 4;
$sotrang = ceil($n/$sodong);
if(!$_GET["p"])
$p = 1;
else
$p = $_GET["p"];
$x = ($p -1)*$sodong;

$lenh1 = "select hinh,tenlaptop,tenhanglaptop,tenloai,concat(soluong,' Cái') as soluong,concat(format(dongia,0),' VNĐ') as dongia,mota from laptop,hanglaptop,loailaptop where laptop.mahanglaptop = hanglaptop.mahanglaptop and laptop.maloailaptop = loailaptop.maloailaptop and tenlaptop like '%$ten%' and laptop.mahanglaptop = '$hang' limit $x,$sodong";
$kq1 = mysql_query($lenh1);
?>
<form id="tim" name="tim" method="post" action="index.php?act=tk" enctype="multipart/form-data" onsubmit="return  validForm()">
  <table width="550" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF99CC" bgcolor="#FFFF99" style="border-collapse:collapse">
    <tr>
      <td height="40" colspan="2" align="center" bgcolor="#FFFF66"><strong>TÌM KIẾM SẢN PHẨM</strong></td>
    </tr>
    <tr>
      <td width="141" style="padding-left:20px">Tên laptop: 
        <label for="ten"></label>        <label for="tim"></label></td>
      <td width="409" style="padding-left:20px"><input name="ten" type="text" id="ten" size="50" value="<?php   if(isset($_POST["ten"]))echo $_POST["ten"];else echo $ten;   ?>" />        <input type="submit" name="tim2" id="tim2" value="Tìm" onclick="kiemtra()" /></td>
    </tr>
    <tr>
      <td style="padding-left:20px">Hãng laptop: </td>
      <td style="padding-left:20px"><label for="hang"></label>
        <select name="hang" id="hang">
        <?php
		$lenh_hang = "select * from hanglaptop";
		$kq_hang = mysql_query($lenh_hang);
		while($row_hang = mysql_fetch_row($kq_hang))
		{
			if($hang == $row_hang[0])
						echo " <option value='$row_hang[0]'selected>$row_hang[1]</option>";
						else
						echo " <option value='$row_hang[0]'>$row_hang[1]</option>";
						
			
		}
		
		
		?>
       
      </select></td>
    </tr>
    <tr>
      <td colspan="2" style="padding-left:20px"><?php if(isset($_POST["ten"]))echo $tb;   ?></td>
    </tr>
    <tr>
      <td colspan="2">
      <?php
	  if(isset($_POST["ten"])||isset($_GET["ten"]))
	  {
	  echo"<table width='100%' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#FF99CC' bgcolor='#FFFFCC' style='border-collapse:collapse'>
  <tr>
    <td height='40' colspan='2' align='center' bgcolor='#FFFF99'><strong>THÔNG TIN SẢN PHẨM</strong></td>
  </tr>";
  while($row = mysql_fetch_row($kq1))
  {
  $nd = str_replace($ten,'<span style="background:#FFFF00; color:#FF0000">'.$ten.'</span>',$row[6]);
    $th = str_replace($ten,'<span style="background:#FFFF00; color:#FF0000">'.$ten.'</span>',$row[2]);
  echo"<tr>
    <td width='150' id='noidung2'><img src='laptop/$row[0]' width='150' height='100' /></td>
    <td width='400' id = 'noidung' valign='top'><font color='#000066'><b>Tên laptop:</b></font> $row[1]<br><font color='#FF0000'>Hãng laptop:</font> $th<br><font color='#00FF00'>Loại laptop:</font> $row[3] - $nd - $row[5]<br><font color='#FF00FF'>Mô tả:</font><font color='#0000CC'> $row[6]</font></td>
  </tr>";
  }
echo"</table>";
	}  
	  ?>
      
      </td>
    </tr>
  </table>
  <p align="center">
<?php
if(isset($_POST["ten"])||isset($_GET["ten"]))
{
for($i = 1; $i <= $sotrang; $i++)
{
	if($i == $p)
	{
		echo $i."&nbsp;";
	}
	else
	{
	?>
	<a href="index.php?act=tk&ten=<?php  echo $ten;   ?>&hang=<?php  echo $hang;   ?>&p=<?php echo $i;    ?>"><?php echo $i;    ?></a>
	<?php
	}
}
}

?>
</p>
</form>
</body>
</html>
